package com.taldh.springboot.config;

import com.taldh.springboot.Okay;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(OkayProperties.class)
//@ConditionalOnClass()
@ConditionalOnWebApplication
public class OkayStarterAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    /**
     * 当存在okay.config.enable=true的配置时,这个Okay bean才生效
     */
//    @ConditionalOnProperty(prefix = "okay.config", name = "enable", havingValue = "true")
    public Okay defaultStudent(OkayProperties okayProperties) {
        System.out.println("print spring auto configuration.");
        Okay okay = new Okay();
        okay.setPlatform(okayProperties.getPlatform());
        okay.setChannel(okayProperties.getChannel());
        okay.setEnable(okayProperties.getEnable());
        return okay;
    }

}
